import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/labels/index.dart';
import 'package:im_flutter_sdk_example/jsonserialize/personal_center/my_collect_data.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';

import 'widgets/collection.dart';

class CollectionList extends StatefulWidget {
  @override
  _CollectionListState createState() => _CollectionListState();
}

class _CollectionListState extends State<CollectionList> {
  List<MyCollectData> collectData = [];
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      getData();
    });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('我的收藏')),
      body: Container(
        color: Colors.white,
        child: SingleChildScrollView(
            child: Column(
          children: collectData
              .map((item) => CollectionItem(item: item, getData: getData))
              .toList(),
        )),
      ),
    );
  }

  //收藏列表
  void getData() async {
    var result = await G.req.user.reqMyCollect();
    collectData.clear();
    result.data['data'].forEach((item) {
      MyCollectData collectItem = MyCollectData.fromJson(item);
      collectData.add(collectItem);
    });
    this.setState(() {});
  }
}
